<?php
header("Content-type: text/html; charset=utf-8"); 
include_once "DB.class.php";
// $filepath =  $_SERVER['DOCUMENT_ROOT'];  
  $filename = 'synonym.html';
  $handle  = fopen ($filename, "r");
  $bigstr  = '';
  //从文本取出数据拼接字符串
  while (!feof ($handle)) 
  { 
	    $buffer  = fgets($handle, 4096);
	    $str = $buffer;
	    if (strpos($str,'<tr height="19" style="height:14.25pt">')) {
	       $bigstr.='|';
	      
	    	# code...
	     }elseif (strpos($str,'</td>')) {
	     	$bigstr.=$str.',';
	     	# code...
	     }

    }

 fclose ($handle);
 //分割字符串为数组
$bigstr=htmlspecialchars(strip_tags($bigstr)) ;
$arr = explode('|', $bigstr);
foreach ($arr as $k => $v) {
	$v=rtrim($v,',');
	$array[$k]=explode(',',$v);
	# code...
}
//插入数据库
foreach ($array as $k => $v) {
   foreach ($v as $kk => $vv) {

   	$sql="insert into synonym (synonym_id,synonym) value ($k,'".trim($vv)."')";
   	$re=$DB->exec($sql);
   	# code...
   }
	# code...
}
if ($re) {
	echo 'ok';
	# code...
}


